DECLARE @xml XML

SET @xml = 
(
    SELECT
        SegmentId       = ISNULL(SegmentId,0)
    ,   SegmentName     = CAST('<![CDATA[' + ISNULL(SegmentName,'') + ']]>' AS xml)
    ,   SortOrdinal     = ISNULL(CAST(SortOrdinal AS varchar(16)),'')
    ,   CreateDate      = ISNULL(Core.dbo.fDateFormat(@GlobalDateFormat,CreateDate),'')
    ,   ParentSegmentId
    ,   ClientId        = ISNULL(ClientId,'')
    ,   IsActive        = ISNULL(IsActive,0)
    ,   SegmentBranch   = CAST(dbo.fGetWebXmlString('SegmentBranch',SegmentId) AS xml)
    FROM
        Segment
    WHERE
        SegmentId = @SegmentId
    FOR XML AUTO, ELEMENTS
)

SELECT @xml
